﻿using HcyWpfApp1.Model;
using Microsoft.Toolkit.Mvvm.ComponentModel;
using Microsoft.Toolkit.Mvvm.Input;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace HcyWpfApp1.ViewModel
{
    public class UserViewModel: ObservableObject
    {
        public UserViewModel()
        {
            Status = "Hello";
            ExecCommand = new AsyncRelayCommand(ExecAsync);
            UserInfoList = GetUserList();
        }
        private string _status;

        public string Status
        {
            get => _status;
            set => SetProperty(ref _status, value);
        }
        private int _progressValue;

        public int ProgressValue
        {
            get => _progressValue;
            set => SetProperty(ref _progressValue, value);
        }
        public ICommand ExecCommand { get; }

        public ICommand PrevPageCommand { get; }

        private async Task ExecAsync()
        {
            Status = "Processing...";

            await Task.Run(async () =>
            {
                for (int i = 0; i <= 100; i++)
                {
                    ProgressValue = i;

                    await Task.Delay(100);
                }
            });
            Status = "Complete";
        }

        public List<UserInfoModel> UserInfoList { get; set; }

        private List<UserInfoModel> GetUserList() {
            List<UserInfoModel> userInfoModels = new List<UserInfoModel>();
            for (int i = 0; i <= 100; i++) { 
               UserInfoModel userInfo = new UserInfoModel();    
                userInfo.Id = i;
                userInfo.UserName = i.ToString();
                userInfo.Address = i.ToString();
                userInfo.Phone = i.ToString();
                userInfoModels.Add(userInfo);
            }
            return userInfoModels;
        }
    }
}
